package client;

import msg.MsgRegistration;

/**
 *
 * @author tomek
 */
public class Registration {

    private static gui.RegistrationGui myGui;
    private MsgRegistration ms;
    private Connection c;
    
    public Registration() {
        myGui = new gui.RegistrationGui(this);
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                myGui.showGui();
            }
        });    
    }
    
    public void sendRegistrationRequest(String login, String passwdHash, String email, String firstName, String lastName, String birthYear, String city) {
        ms = new MsgRegistration(login, passwdHash, email, firstName, lastName, birthYear, city);
        
       // int r = 1;
        c = new Connection(1025);
        int r = c.register(ms);
        if (r == 0) {
            myGui.showErrorDialog();
        }
        else {
            Client.saveProperties(login, passwdHash);
            myGui.showConfirmationDialogAndDispose();
            Client.setLogin(login);
            Client.setHash(passwdHash);
            new UsersList();
        }
    }
}
